package Semester_3.src.AJAX;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.*;
import java.util.Properties;

public class DataSelect {
    public static String select(String name) {
        String index = "";
        String url = "jdbc:mysql://localhost:3306/jdbc_demo?serverTimezone=UTC";
        String username = "root";
        String password = "@gaoyang1";
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        Statement statement = null;
        try {
            statement = connection.createStatement();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        String sql = "select * from user";
        ResultSet set = null;
        try {
            set = statement.executeQuery(sql);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        while (true){
            try {
                if (!set.next()) break;
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
            String u_name = null;
            try {
                u_name = set.getString(2);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
            if(u_name.equals(name)){
                index = "true";
            } else {
                index = "false";
            }
        }
        return index;
    }
}
